/**
 * @Author:  renyc
 * @Date: 2023年3月6日16:49:06
 */
'use strict';

// import * as Cesium from "cesium/Cesium";
import DataSource from "../DataSource";
import SourceType from "../../type/SourceType";
import {SourceEventType} from "../../../event/EventType";
import GeoJsonProvider from "../../provider/vector/GeoJsonProvider";

// GEOJSON_OPTS = {
//     SOUCE_OPTS,

//     url : http://host:port/service/data.json
// }
/**
 * @description 要素类(Feature)数据源
 * 派生类
 * 1) GeoJsonSource
 * 2) CsvSource
 * 3) WebFeatureSource
 */
class FeatureSource extends DataSource {

    constructor(name, options){

        if(!options){
            throw new Error('FeatureSource: options无效');
        }
        if(!options.url){
            throw new Error('FeatureSource: url为空');
        }

        super(name, options);
        
        this._type = SourceType.FEATURE;
        this._provider = undefined

        this._url = options.url;

        this._json = undefined;     //fetch结果的json数据
        /**
         *_delegate的值为Promise类型，具体为Promise.<FeatureSource>类型
         */
        //this._delegate = Cesium.GeoJsonDataSource.load(this._url, options);

        // this._delegate = null;
        // this._cesiumGeoJsonDataSource = new Cesium.GeoJsonDataSource(name);
    }

    /**
     * 获取Json数据
     */
    get json(){
        return this._json;
    }

    /**
     * 返回内部delegate属性
     */
    get delegate(){
        return this._delegate;
    }

    /**
     * @description 获取数据
     * @protected
     * @Override
     */
    fetch(){}


    /**
     * @description 清空Source
     * @protected
     * @override
     */
    cleanup(){
        if(this._delegate){
            this._delegate.then(dataSource=>{
                dataSource.entities.removeAll();
            })
        }
    }
}

export default FeatureSource;